home *** CD-ROM | disk | FTP | other *** search
/ Singles Flirt Up Your Life! (German) / Singles Flirt Up Your Life.iso / data1.cab / Statemachine / phoneChar.lua < prev    next >
Text File  |  2004-01-29  |  10KB  |  370 lines

  1. -- phone character state machine
  2. beginStateMachine()
  3.     
  4.     onEnter(function(msg)
  5.         local phone = getStateObjectFromID(msg.sender);
  6.         storeStateObject("phone", phone);
  7.         
  8.         if (phone) then
  9.             -- phone does exist
  10.             local actionPointName = retrieveData("actionPointName");
  11.             local actionPoint = getParent().getFreeActionPoint(phone, actionPointName);
  12.  
  13.             --if (getParent().isOneActionPointLocked(phone)) then
  14.             if (not actionPoint) then
  15.                 -- action point is locked
  16.                 getParent().setEmoticon(EMOTICON_CANNOT, EMOTICON_DELAY);
  17.                 sendMsg("emoThink", getParent().walkSO);
  18.                 exitStateMachine();
  19.             else
  20.                 getParent().lockActionPoint(phone, actionPointName);
  21.             end
  22.         else
  23.             -- phone does not exist anymore
  24.             getParent().setEmoticon(EMOTICON_CANNOT, EMOTICON_DELAY);
  25.             sendMsg("emoThink", getParent().walkSO);
  26.             exitStateMachine();
  27.         end
  28.         
  29.         freeHands(getParent());
  30.                 
  31.     end )
  32.     
  33.     onExit(function(msg)
  34. --        local phone = retrieveStateObject("phone");
  35. --        getParent().unlockActionPoints(phone);
  36. --        getParent().stopAllActivities(phone);
  37. --        removeStateObject("phone");
  38.         
  39.         unlockAll("phone");        
  40.             
  41.     end )
  42.     
  43.     -----------------------------------------------------------------------------------------
  44.     -----------------------------------------------------------------------------------------
  45.     -----------------------------------------------------------------------------------------
  46.     
  47.     
  48.     state("callFriendsStart")
  49.     
  50.         onEnter(function(msg)
  51.             startAnimation("phoneStart");
  52.             this.actionComplete();
  53.             
  54.             sendDelayedMsgThis("takeHandle", 800);
  55.         end )    
  56.             
  57.         onMsg("takeHandle", function(msg)
  58.             local phone = retrieveStateObject("phone");            
  59.             local handle = phone.createGameObject("handle");
  60.             getParent().attachRightObjectHolder(handle);            
  61.         end )    
  62.  
  63.  
  64.         onMsg("end", function(msg)
  65.             if testCancel() then
  66.                 setState("callFriendsStop");
  67.             else
  68.                 setState("callFriends");
  69.             end
  70.         end )    
  71.  
  72.     state("callFriends")
  73.     
  74.         onEnter(function(msg)
  75.             startAnimation("phoneLoop");
  76.             
  77.             local phone = retrieveStateObject("phone");            
  78.             local callFriends = getParent().startActivity("callFriends", phone);
  79.             local length, scale = getActivityLength(callFriends);
  80.  
  81.             sendDelayedMsgThis("talk", random(5000, 10000));
  82.             sendDelayedMsgThis("complete", length);
  83.             sendDelayedMsgThis("testCancel", CANCEL_POLLING_INTERVAL);
  84.             
  85. --            getParent().getGameObjectServer().payMoney(1);
  86.         end )
  87.         
  88.         onExit(function(msg)
  89.             local phone = retrieveStateObject("phone");
  90.             getParent().stopAllActivities(phone);
  91.         end )
  92.         
  93.         onMsg("talk", function(msg)
  94.             print("talk in wso  " .. getParent().getCharacterName());
  95.             sendMsg("talk", getParent().mimicSO);
  96.             sendDelayedMsgThis("talk", random(5000, 10000));
  97.         end )
  98.  
  99.                 
  100.         onMsg("complete", function(msg)
  101.             setState("callFriendsStop");
  102.         end )            
  103.  
  104.         onMsg("testCancel", function(msg)
  105.             if testCancel() then
  106.                 sendMsgThis("complete");
  107.             else
  108.                 sendDelayedMsgThis("testCancel", CANCEL_POLLING_INTERVAL);
  109.             end
  110.         end )            
  111.  
  112.  
  113.         onMsg("end", function(msg)
  114.             if testCancel() then
  115.                 sendMsgThis("complete");
  116.             else
  117.                 startAnimation("phoneLoop");
  118.             end
  119.         end )    
  120.         
  121.         
  122.     state("callFriendsStop")
  123.     
  124.         onEnter(function(msg)
  125.             startAnimation("phoneStart", false, -1.0);
  126.             
  127.             sendDelayedMsgThis("dropHandle", 1600);
  128.         end )    
  129.             
  130.         onMsg("dropHandle", function(msg)
  131.             freeHands(getParent());
  132.             --getParent().detachRightObjectHolder();            
  133.         end )    
  134.  
  135.  
  136.         onMsg("end", function(msg)
  137.             exitAndGoAway();
  138.         end )    
  139.  
  140.     -----------------------------------------------------------------------------------------
  141.     -----------------------------------------------------------------------------------------
  142.     -----------------------------------------------------------------------------------------
  143.         
  144.     
  145.     state("callPizzaStart")
  146.     
  147.         onEnter(function(msg)
  148.             startAnimation("phoneStart");
  149.             this.actionComplete();
  150.             
  151.             sendDelayedMsgThis("takeHandle", 800);
  152.         end )    
  153.             
  154.         onMsg("takeHandle", function(msg)
  155.             local phone = retrieveStateObject("phone");            
  156.             local handle = phone.createGameObject("handle");
  157.             getParent().attachRightObjectHolder(handle);            
  158.         end )    
  159.  
  160.  
  161.         onMsg("end", function(msg)
  162.             if testCancel() then
  163.                 setState("callPizzaAborted");
  164.             else
  165.                 setState("callPizza");
  166.             end
  167.         end )    
  168.  
  169.     state("callPizza")
  170.     
  171.         onEnter(function(msg)
  172.             startAnimation("phoneLoop");
  173.             
  174.             local phone = retrieveStateObject("phone");            
  175.             local callPizza = getParent().startActivity("callPizza", phone);
  176.             local length, scale = getActivityLength(callPizza);
  177.  
  178.             sendDelayedMsgThis("talk", random(5000, 10000));
  179.             sendDelayedMsgThis("complete", length);
  180.             sendDelayedMsgThis("testCancel", CANCEL_POLLING_INTERVAL);
  181.             
  182. --            getParent().getGameObjectServer().payMoney(1);
  183.         end )
  184.         
  185.         onExit(function(msg)
  186.             local phone = retrieveStateObject("phone");
  187.             getParent().stopAllActivities(phone);
  188.         end )
  189.         
  190.         onMsg("talk", function(msg)
  191.             print("talk in wso  " .. getParent().getCharacterName());
  192.             sendMsg("talk", getParent().mimicSO);
  193.             sendDelayedMsgThis("talk", random(5000, 10000));
  194.         end )
  195.  
  196.         onMsg("canceled", function(msg)
  197.             setState("callPizzaAborted");
  198.         end )            
  199.                 
  200.         onMsg("complete", function(msg)
  201.             setState("callPizzaStop");
  202.         end )            
  203.  
  204.         onMsg("testCancel", function(msg)
  205.             if testCancel() then
  206.                 sendMsgThis("canceled");
  207.             else
  208.                 sendDelayedMsgThis("testCancel", CANCEL_POLLING_INTERVAL);
  209.             end
  210.         end )            
  211.  
  212.  
  213.         onMsg("end", function(msg)
  214.             if testCancel() then
  215.                 sendMsgThis("canceled");
  216.             else
  217.                 startAnimation("phoneLoop");
  218.             end
  219.         end )
  220.         
  221.         
  222.     state("callPizzaStop")
  223.     
  224.         onEnter(function(msg)
  225.             startAnimation("phoneStart", false, -1.0);
  226.             
  227.             sendDelayedMsgThis("dropHandle", 1600);
  228.         end )    
  229.             
  230.         onMsg("dropHandle", function(msg)
  231.             freeHands(getParent());
  232.             --getParent().detachRightObjectHolder();            
  233.         end )    
  234.  
  235.  
  236.         onMsg("end", function(msg)
  237.             if (testCancel()) then
  238.                 exitStateMachine();
  239.             else
  240.                 local character = this.getParent();
  241.                 local staircase, actionPoint = getReachableObjectWithBehavior(character, "staircase", {"topStep"}, true)
  242.                 
  243.                 
  244. --                local staircases = getParent().getObjectsWithBehavior("staircase");
  245. --                local staircase = staircases[1];
  246. --                if (not staircase) then
  247. --                    print("no staircase");
  248. --                    exitStateMachine();
  249. --                    return
  250. --                end
  251. --                -- walk to the closest action point
  252. --                local actionPoint = character.getFreeActionPoint(staircase, "topStep");
  253.                 
  254.                 
  255.                 --local actionPoint = character.getClosestFreeActionPointToClickPoint(staircase, {"topStep"});
  256.                 if (actionPoint) then
  257.                 -- get the walk state object
  258.                     local wso = character.walkSO;
  259.                     -- create state machine contexts
  260.                     local wsoContext = StateMachineContext();
  261.                     -- store the action point
  262.                     --wsoContext.storeData("actionPointName", actionPoint.getName());
  263.                     --wsoContext.storeStateObject("staircase", staircase);
  264.                     if (wso.walkToActionPoint(actionPoint)) then
  265.                         print("queue staircaseChar.goGetPizza");
  266.                         wso.queueStateMachine("staircaseChar.goGetPizza", staircase, wsoContext);
  267.                         exitStateMachine();
  268.                     else
  269.                         print("no path found");
  270.                         character.setEmoticon(EMOTICON_NOPATH, EMOTICON_DELAY);
  271.                         sendMsg("emoThink", character.walkSO);
  272.                         setState("callPizzaAborted");
  273.                     end
  274.                 else
  275.                     print("no action point found");
  276.                     character.setEmoticon(EMOTICON_CANNOT, EMOTICON_DELAY);
  277.                     sendMsg("emoThink", character.walkSO);
  278.                     setState("callPizzaAborted");
  279.                 end
  280.             end
  281.         end )
  282.             
  283.     state("callPizzaAborted")
  284.     
  285.         onEnter(function(msg)
  286.             startAnimation("phoneStart", false, -1.0);
  287.             
  288.             sendDelayedMsgThis("dropHandle", 1600);
  289.         end )    
  290.             
  291.         onMsg("dropHandle", function(msg)
  292.             freeHands(getParent());
  293.             --getParent().detachRightObjectHolder();            
  294.         end )    
  295.  
  296.  
  297.         onMsg("end", function(msg)
  298.             exitStateMachine();
  299.         end )
  300.  
  301.  
  302. --    state("callPizza")
  303. --    
  304. --        onEnter(function(msg)
  305. --            startAnimation("phone");
  306. --            this.actionComplete();
  307. --        end )        
  308. --
  309. --        onMsg("queue", function(msg)
  310. --            exitStateMachine();
  311. --        end )    
  312. --
  313. --        onMsg("end", function(msg)
  314. --            if (testCancel()) then
  315. --                exitStateMachine();
  316. --            else
  317. --                local staircases = getParent().getObjectsWithBehavior("staircase");
  318. --                local staircase = staircases[1];
  319. --                if (not staircase) then
  320. --                    print("no staircase");
  321. --                    exitStateMachine();
  322. --                    return
  323. --                end
  324. --                
  325. --                local character = this.getParent();
  326. --                
  327. --                -- walk to the closest action point
  328. --                local actionPoint = character.getFreeActionPoint(staircase, "topStep");
  329. --                --local actionPoint = character.getClosestFreeActionPointToClickPoint(staircase, {"topStep"});
  330. --                if (actionPoint) then
  331. --                -- get the walk state object
  332. --                    local wso = character.walkSO;
  333. --                    -- create state machine contexts
  334. --                    local wsoContext = StateMachineContext();
  335. --                    -- store the action point
  336. --                    --wsoContext.storeData("actionPointName", actionPoint.getName());
  337. --                    --wsoContext.storeStateObject("staircase", staircase);
  338. --                    if (wso.walkToActionPoint(actionPoint)) then
  339. --                        wso.queueStateMachine("staircaseChar.goGetPizza", staircase, wsoContext);
  340. --                    else
  341. --                        print("no path found");
  342. --                        character.setEmoticon(EMOTICON_NOPATH, EMOTICON_DELAY);
  343. --                        sendMsg("emoThink", character.walkSO);
  344. --                    end
  345. --                else
  346. --                    print("no action point found");
  347. --                    character.setEmoticon(EMOTICON_CANNOT, EMOTICON_DELAY);
  348. --                    sendMsg("emoThink", character.walkSO);
  349. --                end
  350. --            end
  351. --        end )    
  352. --
  353. --    state("callOffice")
  354. --    
  355. --        onEnter(function(msg)
  356. --            startAnimation("phone");
  357. --            this.actionComplete();
  358. --        end )        
  359. --
  360. --        onMsg("queue", function(msg)
  361. --            exitStateMachine();
  362. --        end )    
  363. --
  364. --        onMsg("end", function(msg)
  365. --            exitStateMachine();
  366. --        end )    
  367.  
  368.                 
  369. endStateMachine()
  370.